//------------------------------------------------------------------------------
// <copyright file="RpcRequest.h" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

#pragma once

#include "RpcAnnotations.h"
#include <RpcArchiveImpl.h>
#include <RpcArchiveImplFactory.h>

namespace Microsoft { namespace Internal { namespace GamesTest { namespace Rpc { namespace Server
{
	/// <summary>
	/// This class represents an incoming request from a client to invoke a method.
	/// </summary>
	class RpcRequest
	{
	private:
		std::wstring m_methodName;
		RpcArchiveImplPtr m_parameters;
		RequestIdType m_requestId;

	public:
		/// <summary>
		/// Initializes a new instance of the RpcRequest class.
		/// </summary>
		RpcRequest():
			m_requestId(0),
			m_parameters(RpcArchiveImplFactory::EmptyPointer())
		{
		}

		/// <summary>
		/// Initializes a new instance of the RpcRequest class.
		/// </summary>
		RpcRequest(std::wstring&& initMethodName, RpcArchiveImplPtr initParameters):
			m_requestId(0),
			m_methodName(std::move(initMethodName)),
			m_parameters(std::move(initParameters))
		{
		}

		/// <summary>
		/// This method is used to create an RpcRequest from a JsonObject.  A failure code
		/// will be returned if the parse operation fails.
		/// </summary>
		/// <param name="requestObject">The JsonObject that contains the data for this RpcRequest.</param>
		/// <param name="result">A pointer to the RpcRequest to be populated.</param>
		static GAMESTEST_ANNOTATE_HRESULT_METHOD HRESULT Parse(const std::wstring& requestObject, RpcRequest* result);

		/// <summary>
		/// This method is used to "peek" at methodName in serialized request without deserializing the JSON.
		/// </summary>
		/// <param name="messageObject">The serialized RpcMessage containing serialized RpcRequest.</param>
		/// <param name="methodName">The method name extracted from the serialized text without using JSON parser.</param>
		static GAMESTEST_ANNOTATE_HRESULT_METHOD HRESULT PreParse(const std::wstring& requestObject, std::wstring& methodName);

		/// <summary>
		/// Serializes this object to the provided string.
		/// </summary>
		GAMESTEST_ANNOTATE_HRESULT_METHOD HRESULT Serialize(std::wstring& result);

		/// <summary>
		/// Gets the name of the method to be invoked on the server-side.
		/// </summary>
		const std::wstring& GetMethodName() const
		{
			return m_methodName;
		}

		void SetMethodName(const std::wstring& value)
		{
			m_methodName = value;
		}

		/// <summary>
		/// Gets or sets the name of the method to be invoked on the server-side.
		/// </summary>
		__declspec(property(get=GetMethodName, put=SetMethodName)) std::wstring& MethodName;

		/// <summary>
		/// Gets the data that was passed in as request parameters.
		/// </summary>
		RpcArchiveImpl& GetParameters()
		{
			return *m_parameters;
		}

		/// <summary>
		/// Sets the data that was passed in as request parameters.
		/// </summary>
		void SetParameters(RpcArchiveImplPtr&& value)
		{
			m_parameters = std::move(value);
		}

		/// <summary>
		/// Gets or sets the data that was passed in as request parameters.
		/// </summary>
		__declspec(property(get=GetParameters)) RpcArchiveImpl& Parameters;

		RequestIdType GetRequestId()
		{
			return m_requestId;
		}

		void SetRequestId(RequestIdType requestId)
		{
			m_requestId = requestId;
		}

		/// <summary>
		/// Gets and sets the Id of this request.
		/// </summary>
		__declspec(property(get=GetRequestId, put=SetRequestId)) RequestIdType RequestId;
	};

}}}}}